package com.sven.idrivingfutureserver.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.sven.idrivingfutureserver.common.Response;
import com.sven.idrivingfutureserver.pojo.SettingDetail;
import com.sven.idrivingfutureserver.pojo.UserInfo;
import com.sven.idrivingfutureserver.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName LoginController
 * @Description
 * @Author 小张
 * @Date 2024/5/29 10:59
 * @Version 1.0
 **/
@SaCheckLogin       //只有登录后，才能进入下面的接口
@RestController
@Slf4j
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 批量生成小程序二维码需要的key
     * @param num 生成的数量
     * @param pwd 密码：kKxbEe3cD632PkbG
     */
    @SaIgnore
    @RequestMapping("/generateQrcodeList")
    public Response generateQrcodeList(@RequestParam("num") Integer num, @RequestParam("pwd") String pwd) {
        return loginService.generateQrcodeList(num, pwd);
    }

    @SaIgnore
    @RequestMapping("/wechatLogin")
    public Response wechatLogin(@RequestParam("code") String code) {
        return loginService.wechatLogin(code);
    }

    // 提交用户授权的用户信息
    @PostMapping("/postUserInfo")
    public Response postUserInfo(UserInfo userInfo) {
        return loginService.postUserInfo(userInfo);
    }

    @RequestMapping("/getUserInfo")
    public Response getUserInfo() {
        return null;
    }

    /**
     * 查询挪车码是否已绑定
     * 绑定：则返回车主预留的挪车信息
     * 未绑定：则提示用户可以绑定信息
     */
    @SaIgnore
    @RequestMapping("/isQrCodeBinging")
    public Response isQrCodeBinging(@RequestParam("qrcode") String qrcode) {
        return loginService.isQrCodeBinging(qrcode);
    }

    /**
     * 解绑二维码
     * @param qrcode 二维码值
     */
    @RequestMapping("/unBindQrCode")
    public Response unBindQrCode(@RequestParam("qrcode") String qrcode) {
        return loginService.unBindQrCode(qrcode);
    }

    /**
     * 绑定二维码
     * @param qrcode 二维码值
     */
    @RequestMapping("/bindQrCode")
    public Response bindQrCode(@RequestParam("qrcode") String qrcode, @RequestParam("plateNumberId") Integer plateNumberId) {
        return loginService.bindQrCode(qrcode, plateNumberId);
    }

    /**
     * 将挪车码与手机号绑定
     */
    @RequestMapping("/bindPhoneNumber")
    public Response bindPhoneNumber(@RequestParam("code") String code, @RequestParam("qrcode") String qrcode) {
        return loginService.bindPhoneNumber(code, qrcode);
    }

    /**
     * 查询我的挪车码
     */
    @RequestMapping("/getMyQrCodes")
    public Response getMyQrCodes() {
        return loginService.getMyQrCodes();
    }

    /**
     * 更换手机号
     * @param code 获取手机号所需的code
     */
    @RequestMapping("/changePhoneNumber")
    public Response changePhoneNumber(@RequestParam("code") String code, @RequestParam("phoneNumberId") Integer phoneNumberId) {
        return loginService.changePhoneNumber(code, phoneNumberId);
    }

    /**
     * 修改或添加车牌号
     * @param plateNumber 修改后的车牌号
     * @param qrcode 对应的挪车码
     */
    @RequestMapping("/changePlateNumber")
    public Response changePlateNumber(@RequestParam("plateNumber") String plateNumber,
                                      @RequestParam("qrcode") String qrcode) {
        return loginService.changePlateNumber(plateNumber, qrcode);
    }

    @RequestMapping("/getMySettingInfo")
    public Response getMySettingInfo(@RequestParam("qrcode") String qrcode) {
        return loginService.getMySettingInfo(qrcode);
    }

    @PostMapping("/updateMySettingInfo")
    public Response updateMySettingInfo(@RequestBody SettingDetail settingDetail) {
        return loginService.updateMySettingInfo(settingDetail);
    }

    /**
     * 根据车牌号查找用户信息
     * @param plateNumber 车牌号
     */
    @RequestMapping("/getUserInfoByPlateNumber")
    public Response getUserInfoByPlateNumber(@RequestParam("plateNumber") String plateNumber) {
        return loginService.getUserInfoByPlateNumber(plateNumber);
    }

    /**
     * 根据二维码查询车主信息
     * @param qrcode 二维码信息
     */
    @SaIgnore
    @RequestMapping("/getUserInfoByQrCode")
    public Response getUserInfoByQrCode(@RequestParam("qrcode") String qrcode) {
        return loginService.getUserInfoByQrCode(qrcode);
    }

    /**
     * 获取用户的隐私号码
     * @param qrcode 扫描的挪车码(避免使用用户id，被爬取信息)
     */
    @RequestMapping("/getPrivacyNumber")
    public Response getPrivacyNumber(@RequestParam("qrcode") String qrcode) {
        return loginService.getPrivacyNumber(qrcode);
    }

    /**
     * 发送短信提醒用户挪车
     * @param qrcode 被提醒人挪车码
     * @param plateNumber 车牌号
     */
    @RequestMapping("/sendSmsToMoveCar")
    public Response sendSmsToMoveCar(@RequestParam("qrcode") String qrcode, @RequestParam("plateNumber") String plateNumber) {
        return loginService.sendSmsToMoveCar(qrcode, plateNumber);
    }

    /**
     * 查询最近的扫码记录 (默认返回最近20条)
     */
    @RequestMapping("/getScanRecords")
    public Response getScanRecords() {
        return loginService.getScanRecords();
    }
}
